<extend name="common" />
<block name="main">
<div class="createpro-main">
    <div class="createpro-bd clear">
        <form id="createproForm" method="post" class="form-horizontal" action="addApi">
        	<input type="hidden" name="pid" value="{$project_id}">
	        <div class="form-group">
	            <label class="col-lg-1 control-label">接口名称</label>
	            <div class="col-lg-4">
	                <input type="text" class="form-control" id="api_name" name="api_name" placeholder="请输入接口名称，如：user.login" autocomplete="off"
	                 required data-bv-notempty-message="此项必填" value="{$api_info.api_name}">
	            </div>
	        </div>
	        <div class="form-group">
	            <label class="col-lg-1 control-label">接口用途</label>
	            <div class="col-lg-4">
	                <input type="text" class="form-control" id="api_intro" name="api_intro" placeholder="请输入接口用途，如：用户登录" autocomplete="off" required data-bv-notempty-message="此项必填" value="{$api_info.api_intro}">
	            </div>
	        </div>
	        <div class="form-group">
	            <label class="col-lg-1 control-label">接口分组</label>
	            <div class="col-lg-2">
	                <select class="form-control" name="group_id" required data-bv-notempty-message="此项必填">
	                	<option value="0">不分组</option>
	                	<foreach name="groups" item="group">
	                		<if condition="$group['group_id'] eq $api_info['group_id']">
	                		<option value="{$group.group_id}" selected>{$group.group_name}</option>
	                		<else />
	                		<option value="{$group.group_id}">{$group.group_name}</option>
	                		</if>
	                	</foreach>
	                </select>
	            </div>
	        </div>
	        <div class="form-group">
	            <label class="col-lg-1 control-label">请求地址</label>
	            <div class="col-lg-4">
	                <input type="text" class="form-control" id="request_url" name="request_url" placeholder="接口地址，如：http://www.test.com/api" autocomplete="off" required data-bv-notempty-message="此项必填" value="{$api_info.request_url}">
	            </div>
	        </div>
	        <div class="form-group">
	            <label class="col-lg-1 control-label">method</label>
	            <div class="col-lg-2">
	                <select class="form-control" name="api_method" required data-bv-notempty-message="此项必填">
	                	<option value="GET">GET</option>
                		<if condition="$api_info['api_method'] eq POST">
	                	<option value="POST" selected>POST</option>
	                	<else />
	                	<option value="POST">POST</option>
	                	</if>
	                </select>
	            </div>
	        </div>
	        <div class="form-group">
	            <label class="col-lg-1 control-label">请求参数</label>
	            <div class="col-lg-11">
	            	<a href="javascript:;" class="btn btn-primary glyphicon glyphicon-plus btn-addrow">添加参数行</a><span>&nbsp&nbsp数组参数请以如下格式填写(数组中不能包含文件参数)：arr,arr.id,arr.name,arr.info,arr.info.addr...</span>
	            	<table class="table table-bordered">
						<thead>
							<tr>
								<td>操作</td>
								<td>参数名称</td>
								<td>参数类型</td>
								<td>参数说明</td>
								<td>是否必填</td>
								<td>默认值</td>
							</tr>
						</thead>
						<tbody class="table-params">
							<foreach name="api_info.param" item="param">
							<tr class="params-row">
								<td>
									<div class="radio">
										<a href="javascript:;" onclick="copyrow(this)" title="复制"><i class="glyphicon glyphicon-file"></i></a>
										<a href="javascript:;" onclick="moveup(this)" title="上移"><i class="glyphicon glyphicon-arrow-up"></i></a>
										<a href="javascript:;" onclick="movedown(this)" title="下移"><i class="glyphicon glyphicon-arrow-down"></i></a>
	      								<a href="javascript:;" onclick="remove(this)" title="删除"><i class="glyphicon glyphicon-remove"></i></a>
	      							</div>
								</td>
								<td class="col-lg-2"><input type="text" class="form-control" name="param_name[]" value="{$param.param_name}"></td>
								<td>
									<select name="param_type[]" class="form-control" style="">
		                                <option value="">参数类型</option>
		                                <if condition="$param['param_type'] eq 'int'">
		                                <option value="int" selected>int</option>
		                                <else />
		                                <option value="int">int</option>
		                                </if>
		                                <if condition="$param['param_type'] eq 'long'">
		                                <option value="long" selected>long</option>
		                                <else />
		                                <option value="long">long</option>
		                                </if>
		                                <if condition="$param['param_type'] eq 'float'">
		                                <option value="float" selected>float</option>
		                                <else />
		                                <option value="float">float</option>
		                                </if>
		                                <if condition="$param['param_type'] eq 'string'">
		                                <option value="string" selected>string</option>
		                                <else />
		                                <option value="string">string</option>
		                                </if>
		                                <if condition="$param['param_type'] eq 'boolen'">
		                                <option value="boolen" selected>boolen</option>
		                                <else />
		                                <option value="boolen">boolen</option>
		                                </if>
		                                <if condition="$param['param_type'] eq 'file'">
		                                <option value="file" selected>file</option>
		                                <else />
		                                <option value="file">file</option>
		                                </if>
		                                <if condition="$param['param_type'] eq 'array'">
		                                <option value="array" selected>array</option>
		                                <else />
		                                <option value="array">array</option>
		                                </if>
		                                <if condition="$param['param_type'] eq 'json'">
		                                <option value="json" selected>json</option>
		                                <else />
		                                <option value="json">json</option>
		                                </if>
		                                <if condition="$param['param_type'] eq 'xml'">
		                                <option value="xml" selected>xml</option>
		                                <else />
		                                <option value="xml">xml</option>
		                                </if>
		                            </select>
								</td>
								<td><input type="text" class="form-control" name="param_intro[]" value="{$param.param_intro}"></td>
								<td>
									<select name="param_must[]" class="form-control" ng-model="in.para_type" style="">
		                                <option value="0">可选</option>
										<if condition="$param['param_must'] eq 1">
		                                <option value="1" selected>必填</option>
		                                <else />
		                                <option value="1">必填</option>
		                                </if>
		                            </select>
				                </td>
								<td><input type="text" class="form-control" name="param_default[]" value="{$param.param_default}"></td>
							</tr>
							</foreach>
						</tbody>
						</table>
	            </div>
	        </div>
	        <div class="form-group">
	            <label class="col-lg-1 control-label">返回示例</label>
	            <div class="col-lg-4">
	                <textarea rows="6" class="form-control" id="return_example" name="return_example" placeholder="请输入返回示例" autocomplete="off">{$api_info.return_example}</textarea>
	            </div>
	        </div>
	        <div class="form-group">
	            <label class="col-lg-1 control-label">返回参数</label>
	            <div class="col-lg-11">
	            	<a href="javascript:;" class="btn btn-primary glyphicon glyphicon-plus btn-addretrow">添加返回参数行</a>
	            	<table class="table table-bordered">
						<thead>
							<tr>
								<td>操作</td>
								<td>参数名称</td>
								<td>参数类型</td>
								<td>参数说明</td>
							</tr>
						</thead>
						<tbody class="table-ret-params">
							<foreach name="api_info.ret_param" item="ret_param">
							<tr class="params-row">
								<td>
									<div class="radio">
										<a href="javascript:;" onclick="copyrow(this)" title="复制"><i class="glyphicon glyphicon-file"></i></a>
										<a href="javascript:;" onclick="moveup(this)" title="上移"><i class="glyphicon glyphicon-arrow-up"></i></a>
										<a href="javascript:;" onclick="movedown(this)" title="下移"><i class="glyphicon glyphicon-arrow-down"></i></a>
	      								<a href="javascript:;" onclick="remove(this)" title="删除"><i class="glyphicon glyphicon-remove"></i></a>
	      							</div>
								</td>
								<td class="col-lg-2"><input type="text" class="form-control" name="ret_param_name[]" value="{$ret_param.ret_param_name}"></td>
								<td>
									<select name="ret_param_type[]" class="form-control" style="">
		                                <option value="">参数类型</option>
		                                <if condition="$ret_param['ret_param_type'] eq 'int'">
		                                <option value="int" selected>int</option>
		                                <else />
		                                <option value="int">int</option>
		                                </if>
		                                <if condition="$ret_param['ret_param_type'] eq 'long'">
		                                <option value="long" selected>long</option>
		                                <else />
		                                <option value="long">long</option>
		                                </if>
		                                <if condition="$ret_param['ret_param_type'] eq 'float'">
		                                <option value="float" selected>float</option>
		                                <else />
		                                <option value="float">float</option>
		                                </if>
		                                <if condition="$ret_param['ret_param_type'] eq 'string'">
		                                <option value="string" selected>string</option>
		                                <else />
		                                <option value="string">string</option>
		                                </if>
		                                <if condition="$ret_param['ret_param_type'] eq 'boolen'">
		                                <option value="boolen" selected>boolen</option>
		                                <else />
		                                <option value="boolen">boolen</option>
		                                </if>
		                                <if condition="$ret_param['ret_param_type'] eq 'file'">
		                                <option value="file" selected>file</option>
		                                <else />
		                                <option value="file">file</option>
		                                </if>
		                                <if condition="$ret_param['ret_param_type'] eq 'array'">
		                                <option value="array" selected>array</option>
		                                <else />
		                                <option value="array">array</option>
		                                </if>
		                                <if condition="$ret_param['ret_param_type'] eq 'object'">
		                                <option value="object" selected>object</option>
		                                <else />
		                                <option value="object">object</option>
		                                </if>
		                                <if condition="$ret_param['ret_param_type'] eq 'json'">
		                                <option value="json" selected>json</option>
		                                <else />
		                                <option value="json">json</option>
		                                </if>
		                                <if condition="$ret_param['ret_param_type'] eq 'xml'">
		                                <option value="xml" selected>xml</option>
		                                <else />
		                                <option value="xml">xml</option>
		                                </if>
		                            </select>
								</td>
								<td><input type="text" class="form-control" name="ret_param_intro[]" value="{$ret_param.ret_param_intro}"></td>
							</tr>
							</foreach>
						</tbody>
						</table>
	            </div>
	        </div>
	        <div class="form-group">
	            <label class="col-lg-1 control-label">错误示例</label>
	            <div class="col-lg-4">
	                <textarea rows="6" class="form-control" id="error_example" name="error_example" placeholder="请输入返回示例" autocomplete="off">{$api_info.error_example}</textarea>
	            </div>
	        </div>
	        <div class="form-group">
	            <label class="col-lg-1 control-label">备注</label>
	            <div class="col-lg-4">
	                <textarea rows="6" class="form-control" id="memo" name="memo" placeholder="请输入备注" autocomplete="off">{$api_info.memo}</textarea>
	            </div>
	        </div>

	        <div class="form-group">
	            <div class="col-lg-1 col-lg-offset-1">
	                <button type="submit" class="btn btn-primary btn-submit col-lg-12">保存</button>
	            </div>
	        </div>
	    </form>
	</div>
</div>
<script language="javascript">
$(function(){
	$('.btn-addrow').on('click',function(){
		var html = '<tr class="params-row">';
			html +='<td>';
			html +='<div class="radio">';
			html +='<a href="javascript:;" onclick="copyrow(this)" title="复制"><i class="glyphicon glyphicon-file"></i></a>&nbsp';
			html +='<a href="javascript:;" onclick="moveup(this)" title="上移"><i class="glyphicon glyphicon-arrow-up"></i></a>&nbsp';
			html +='<a href="javascript:;" onclick="movedown(this)" title="下移"><i class="glyphicon glyphicon-arrow-down"></i></a>&nbsp';
	      	html +='<a href="javascript:;" onclick="remove(this)" title="删除"><i class="glyphicon glyphicon-remove"></i></a>';
	      	html +='</div>';
			html +='</td>';
			html +='<td class="col-lg-2"><input type="text" class="form-control" name="param_name[]" value=""></td>';
			html +='<td>';
			html +='<select name="param_type[]" class="form-control" ng-model="in.para_type" style="">';
		    html +='<option value="">参数类型</option>';
		    html +='<option value="int">int</option>';
		    html +='<option value="long">long</option>';
		    html +='<option value="float">float</option>';
		    html +='<option value="string">string</option>';
		    html +='<option value="boolen">boolen</option>';
			html +='<option value="file">file</option>';
			html +='<option value="array">array</option>';
			html +='<option value="json">json</option>';
			html +='<option value="xml">xml</option>';
		    html +='</select>';
			html +='</td>';
			html +='<td><input type="text" class="form-control" name="param_intro[]" value=""></td>';
			html +='<td><select name="param_must[]" class="form-control" ng-model="in.para_type" style=""><option value="0">可选</option><option value="1">必填</option></select>';
			html +='</td>';
			html +='<td><input type="text" class="form-control" name="param_default[]" value=""></td>';
			html +='</tr>';
		$(".table-params").append(html);
	});

	$('.btn-addretrow').on('click',function(){
		var html = '<tr class="params-row">';
			html +='<td>';
			html +='<div class="radio">';
			html +='<a href="javascript:;" onclick="copyrow(this)" title="复制"><i class="glyphicon glyphicon-file"></i></a>&nbsp';
			html +='<a href="javascript:;" onclick="moveup(this)" title="上移"><i class="glyphicon glyphicon-arrow-up"></i></a>&nbsp';
			html +='<a href="javascript:;" onclick="movedown(this)" title="下移"><i class="glyphicon glyphicon-arrow-down"></i></a>&nbsp';
	      	html +='<a href="javascript:;" onclick="remove(this)" title="删除"><i class="glyphicon glyphicon-remove"></i></a>';
	      	html +='</div>';
			html +='</td>';
			html +='<td class="col-lg-2"><input type="text" class="form-control" name="ret_param_name[]" value=""></td>';
			html +='<td>';
			html +='<select name="ret_param_type[]" class="form-control" ng-model="in.para_type" style="">';
		    html +='<option value="">参数类型</option>';
		    html +='<option value="int">int</option>';
		    html +='<option value="long">long</option>';
		    html +='<option value="float">float</option>';
		    html +='<option value="string">string</option>';
		    html +='<option value="boolen">boolen</option>';
			html +='<option value="file">file</option>';
			html +='<option value="array">array</option>';
			html +='<option value="object">object</option>';
			html +='<option value="json">json</option>';
			html +='<option value="xml">xml</option>';
		    html +='</select>';
			html +='</td>';
			html +='<td><input type="text" class="form-control" name="ret_param_intro[]" value=""></td>';
			html +='</tr>';
		$(".table-ret-params").append(html);
	});
})

function copyrow(row){
	var $tr = $(row).parents('tr');
	$tr.after($tr.clone());
}

function moveup(row){
	var $tr = $(row).parents('tr');
	var $bf_tr = $tr.prev('tr');

	if($bf_tr.length == 0){
		return false;
	}
	else{
		$bf_tr.before($tr);
	}
}

function movedown(row){
	var $tr = $(row).parents('tr');
	var $af_tr = $tr.next('tr');

	if($af_tr.length == 0){
		return false;
	}
	else{
		$af_tr.after($tr);
	}
}

function remove(row){
	var $tr = $(row).parents('tr');
	$tr.remove();
}
</script>
</block>